package com.www.applyword.ui.my;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.www.applyword.R;
import com.www.applyword.base.BaseActivity;
import com.www.applyword.fragment.BrokerFragment;
import com.www.applyword.fragment.BrokerFragment2;
import com.www.applyword.utils.Utils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * author : huang
 * date   : 2019/10/22 0022 16:21
 * version: 1.0
 */
public class MyBrokerageActivity extends BaseActivity {
    @BindView(R.id.tablayout)
    TabLayout tabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    @BindView(R.id.tv_Record_Money)
    TextView tvRecordMoney;
    @BindView(R.id.tv_recharge)
    TextView tvRecharge;
    @BindView(R.id.tv_withdraw)
    TextView tvWithdraw;
    private List<Fragment> fragments = new ArrayList<>();
    private List<String> tabs = new ArrayList<>();

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.my_broker_activity);
        setTitle("我的佣金");
        tvRecordMoney.setText(getIntent().getStringExtra("money") + "元");
        initData();
    }

    private void initData() {
        tabs.clear();
        fragments.clear();
        tabs.add("支出明细");
        tabs.add("收入明细");
        fragments.add(new BrokerFragment());
        fragments.add(new BrokerFragment2());

        //设置TabLayout的模式
        viewPager.setAdapter(new TabAdapter(getSupportFragmentManager()));
        //关联ViewPager和TabLayout
        tabLayout.setupWithViewPager(viewPager);
        viewPager.setOffscreenPageLimit(2);
    }

    @Override
    protected void loadData() {

    }



    @OnClick({R.id.tv_recharge, R.id.tv_withdraw})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_recharge:
                Utils.startActivity(RechargeActivity.class);
                break;
            case R.id.tv_withdraw:
                startActivity(new Intent(this,WithdrawActivity.class).putExtra("money",getIntent().getStringExtra("money")));
             //   Utils.startActivity(WithdrawActivity.class);
                break;
                default:
        }
    }

    class TabAdapter extends FragmentPagerAdapter {
        public TabAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        //显示标签上的文字
        @Override
        public CharSequence getPageTitle(int position) {
            return tabs.get(position);
        }
    }
}
